Skip to content

[Repo Assist] improve: HtmlParser remove dead code and redundant ToLowerInvariant in EmitTag#1756

Merged
dsyme merged 2 commits intomainfrom
repo-assist/improve-htmlparser-dead-code-2026-04-22-e8df0210e46c5935
Apr 23, 2026
Merged

[Repo Assist] improve: HtmlParser remove dead code and redundant ToLowerInvariant in EmitTag#1756
dsyme merged 2 commits intomainfrom
repo-assist/improve-htmlparser-dead-code-2026-04-22-e8df0210e46c5935

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Summary

Three related code-quality improvements in HtmlParser.fs:

1. Dead code removed from EmitTag

The else branch:

else
    x.HasFormattedParent <- x.HasFormattedParent || x.IsFormattedTag

...was always a no-op. It is only reached when IsFormattedTag is false, so the expression simplifies to x.HasFormattedParent <- x.HasFormattedParent || false = x.HasFormattedParent <- x.HasFormattedParent. Removed.

2. Avoid re-computing CurrentTagName() in EmitTag

EmitTag already computes name = x.CurrentTag.ToString().Trim() at line 191. The subsequent IsFormattedTag and IsScriptTag checks were calling CurrentTagName() again (each does another ToString().Trim()). The method now uses name directly:

if name = "pre" then
    x.HasFormattedParent <- not isEnd

x.InsertionMode <-
    if (name = "script" || name = "style") && not isEnd then
        ScriptMode
    else
        DefaultMode

3. Redundant .ToLowerInvariant() removed from IsFormattedTag / IsScriptTag

Tag names are lowercased at read time — ConsTag applies Char.ToLowerInvariant to every character (line 270). The .ToLowerInvariant() calls in the properties were therefore redundant and allocated an extra string on every check (including the many calls in the tokenise function, lines 461–606).

Test Status

  • dotnet run --project build/build.fsproj -t RunTests292 + 489 + 2 tests, 0 failed

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@96b9d4c39aa22359c0b38265927eadb31dcf4e2a

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@96b9d4c39aa22359c0b38265927eadb31dcf4e2a

…n EmitTag

In EmitTag, the else branch was always a no-op: it is only reached when
IsFormattedTag is false, so the assignment was x.HasFormattedParent <- x.HasFormattedParent.
This dead code is removed.

EmitTag now uses the already-computed name directly for formatted/script
tag checks, avoiding two extra CurrentTagName() calls (each does ToString().Trim()).

IsFormattedTag and IsScriptTag also have the redundant .ToLowerInvariant() removed:
tag names are lowercased at read time in ConsTag via Char.ToLowerInvariant.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review April 23, 2026 09:31
@dsyme dsyme merged commit 3b3f825 into main Apr 23, 2026
3 checks passed
@dsyme dsyme deleted the repo-assist/improve-htmlparser-dead-code-2026-04-22-e8df0210e46c5935 branch April 23, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant